I am sure you have been seeing the Kubernetes widely used in technology circles and wanted to explore yourself.But you are overwhelmed with the amount of resources available on the internet, the complexity involved in learning might make you loose interest or hesitant in trying the things out.
Following my recent experience with creating a test bed to learn Kubernetes,I was able to consolidate the steps for setting up a single node cluster quickly and adding a second node at the end.Thanks to this post, I found while searching on Kubernetes resources.
Assuming you already aware of
- Preparing EC2 machines.
- Using security groups or Firewalls.
- looking in to official documentation in case of issues.
Lets begin..
Preparing base machine
Create an EC2 machine with Ubuntu AMI. Attach a security group to the machine with below ports open for communication between the nodes and to use the dashboard later,from the official installation steps here
The machine should now be ready for serving as Master Node
Installing Kubernetes
Following the steps from the linked post at the beginning
Install Docker
Proceeding with the installation of Docker, most used container runtime for Kubernetes
Install Kubernetes
Installation commands for Kubernetes,Kudeadm and Kubelet
Turn off the swap on Ubuntu Server
swap has to be turned off on Ubuntu due to compatibility issues.
Check Docker and Kubernetes Version
Confirm if the installation have been completed as expected
Prepare node using Kubeadm
With all the installation completed we are good to initialize master node using Kubeadm command using the Ec2 Ip address and you can use your custom cidr address,10.244.0.0/16 is used here
The output of the above command shows the successful control-plane initialized message
To use Kubernetes as non-root user we need to run the commands below
Configure cluster networking
We need to install one of the Container Network Interface (CNI) Network providers from here to have the networking exist between the Cluster,Nodes and Pods
We are installing Flannel
Make Master node as Worker
In a single node cluster we need to use taint to run worker pods on Master.
We can check the Pods and Nodes using the commands below.
First deployment
Glad you have come so far , we are good to deploy our first application on to the cluster.
we will deploy hello-world application from google.Once deployed, inorder to use the application from outside the cluster we need to use Nodeport.
For now, we will just run the command instead of dwelling into the details of Nodeport
Post running the commands our service should be run running and access using the EC2hostname
Scaling the service
With everything setup and working we can try scaling up our application by using replica sets.
This command would increases the pods to 6 and we confirm this by refreshing the above endpoint,which randomly connects to any one of the running pods.
Delete deployment
You can use below cleanup commands to tear down the deployment.
Adding the second node
If you are interested to venture further, we can join one more Ubuntu EC2 as the second node.
Follow all the steps same as Master node preparation until you initialize with Kubeadm.
Then get the join command from the Master node using
Run the command on the new EC2 machine and we should see the two nodes serving in the cluster.
Please note the ports which had to be opened for the communication.
Conclusion
Great work if you reached so far and completed the set up of Kubernetes cluster,this setup can serve you in exploring most of the features and learn new things.